# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.bequant_v2.kr_rest.constants import (quote_currency_list,
                                                        native_quote_currency_list,
                                                        coin_list)


def from_native_currency(native_currency):
  assert type(native_currency) is str
  assert native_currency.upper() == native_currency, native_currency
  assert native_currency in coin_list, native_currency
  if native_currency == 'BSV':
    currency = 'BCHSV'
  elif native_currency == 'BCH':
    currency = 'BCHABC'
  else:
    currency = native_currency
  if currency == 'USD':
    currency = 'USDT'
  return currency


def to_native_currency(currency):
  assert type(currency) is str
  if currency == 'BCHSV':
    native_currency = 'BSV'
  elif currency == 'BCHABC':
    native_currency = 'BCH'
  else:
    native_currency = currency
  if native_currency == 'USDT':
    native_currency = 'USD'
  assert native_currency in coin_list, currency
  return native_currency


class BequantCurrency(NativeCurrency):
  _exchange = 'Bequant'

  def __init__(self, currency, native_currency):
    assert native_currency in coin_list, (currency, native_currency)
    assert native_currency.upper() == native_currency, (currency, native_currency)
    assert to_native_currency(currency) == native_currency, (currency, native_currency)
    super().__init__(currency, native_currency)

  @classmethod
  def FromStrCurrencyImpl(cls, currency_str, current_datetime):
    return cls(currency_str, to_native_currency(currency_str))

  @classmethod
  def FromStrNativeCurrencyImpl(cls, native_currency_str, current_datetime):
    return cls(from_native_currency(native_currency_str), native_currency_str)
